export const SEARCH_OPERATOR = {
  NOT_EQ: 'NotEqualTo',
  EQ: 'EqualTo',
  CONTAIN: 'Contains',
  IS_FALSE: 'IsFalse',
  TYPE_HINT: {
    STRING: 'String',
    BIT: 'Single'
  },
  ASCENDING: 'Ascending',
  LOGICAL: {
    AND: 'And',
    OR: 'Or'
  }
};

export class SortItem {
  // @ts-ignore
  Name: string;
  Direction = SEARCH_OPERATOR.ASCENDING;
}

export class IdFilter {
  // @ts-ignore
  IncludeOnly: number[];
  // @ts-ignore
  ExcludeAny: number[];
}

export class SearchCondition {
  // @ts-ignore
  Fields: string[];
  // @ts-ignore
  SortItems: SortItem[];
  IdFilter: IdFilter;
  FilterSet: FilterSet;

  constructor(fields: string[], sortItems: SortItem[], includeOnly?: number[], excludeAny?: number[]) {
    this.IdFilter = new IdFilter();
    this.FilterSet = new FilterSet();

    // @ts-ignore
    this.Fields = fields;
    this.SortItems = sortItems;

    if (Array.isArray(includeOnly)) {
      this.IdFilter.IncludeOnly = includeOnly;
    }

    if (Array.isArray(excludeAny)) {
      this.IdFilter.ExcludeAny = excludeAny;
    }
  }
}

export class FilterSet {
  LogicalOperator = SEARCH_OPERATOR.LOGICAL.AND;
  FilterSets = [];
  FilterItems: FilterItem[] = [];
}

export interface FilterItem {
  FieldName: string;
  Value: any;
  Operator: string;
  TypeHint: string;
}

export interface SearchParams {
  skip?: number;
  take?: number;
  searchCondition: SearchCondition;
}
